<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, 
initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>Document</title>
</head>
<body>
	<button id="addBtn">+</button>
	<span id="num">0</span>
	<span id="num2">0</span>
	<button id="minusBtn">-</button>
	<script src="./node_modules/redux/dist/redux.js"></script>
	<script>
		let reducer = (state,action)=>{
			switch (action.type) {
				case "ADD":
					return Object.assign( {},state,{ now: state.now+action.num } );
					break;
				case "MINUS":
					return Object.assign( {},state,{ now: state.now-1 } );
					break;
				default:
					return state
					break;
			}
		};

		// 创建 store
		let store = Redux.createStore( reducer,{now:0} );
		
		store.subscribe(()=>{
			num.innerHTML = store.getState().now;
			num2.innerHTML = store.getState().now;
		})

		addBtn.onclick = function(){
			store.dispatch({type:"ADD"});
		}
		minusBtn.onclick = function(){
			store.dispatch({type:"MINUS",num:Math.random()})
		}

	</script>
</body>
</html>